<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 150px;
            margin: 100px auto;
            background-color: skyblue;
            border-radius: 50%;
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 150px;

        }

        a {
            display: block;
            width: 100px;
            margin: 0 auto;
            color: #0071bc;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <div class="box">
        <span id="second">5</span>秒后跳转
    </div>
    <a href="./跳转至页面.html">点击链接跳转</a>
    <script>

        // 1. 定时跳转
        // var time = 5;
        // var timer = setTimeout(jump, 1000);
        // function jump() {
        //     if (time > 1) {
        //         time--;
        //         setTimeout(jump, 1000);
        //         return box.innerHTML = time + '秒后跳转';
        //     } else {
        //         clearTimeout(timer);
        //         return location.href = "./跳转至页面.html";
        //     }
        // }

        // 2. 定时跳转
        function goto(url) {
            var second = document.getElementById('second');
            var num = +second.innerHTML;

            if (num <= 1) {
                clearTimeout(timer);
                return location.href = url;
            }

            setTimeout(function () {
                goto(url);
            }, 1000);
            return second.innerHTML = --num;
        }

        var timer = setTimeout(function () {
            goto('./跳转至页面.html');
        }, 1000);
        var box = document.querySelector('.box');

    </script>

</body>

</html>